package de.koller.faculae.engine.planet;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;

public class Planet {

	private PlanetSurface surface = new PlanetSurface( 100 );
	
	public void resurface() {
		surface = new PlanetSurface( 100 );
	}
	
	public void renderThis( Graphics2D g ) {
		g.setColor( Color.WHITE );
		
		final int facettes = 1000;
		final float rd = (float)(2f*Math.PI) / (float)facettes;
		for( float r = 0; r < 2*Math.PI; r += rd ) {
			float ha = surface.heightAt( r - rd );
			float hb = ha; //surface.heightAt( r );
			g.draw( new Line2D.Double( 
					Math.cos( r ) * ha, Math.sin( r ) * ha, 
					Math.cos( r ) * hb, Math.sin( r ) * hb ) );
		}
		
		g.setColor( Color.BLUE );
		for( int i = 0; i < surface.heights.length; i++ ) {
			float d = 2f*(float)Math.PI / surface.heights.length * i;
			g.draw( new Line2D.Double( 
					0, 0, 
					Math.cos( d ) * (surface.arrayVal( i ) + surface.radius), 
					Math.sin( d ) * (surface.arrayVal( i ) + surface.radius) ) );
		}
	}
	
}
